<template>
	<view class="main-contanier">
		<view class="head-box">
			新闻公告
		</view>
		<view class="main-box">
			<NoiceItem :list="listData" @clickItem="goDetail"></NoiceItem>
		</view>
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
	import {
		Platform,
		Storage_Key,
		ProjectStates,
		ProjectKeys,
	} from '@/static/config.js';
	import {
		GetProjectStatetype,
	} from '@/common/util.js';
	import NoiceItem from "@/pages/notice/components/notice-item/notice-item.vue"
	import request from '@/common/request.js';
	let that;
	export default {
		components: {
			NoiceItem,
		},
		// props: ['data'], //数据
		data() {
			return {}
		},
		data() {
			return {
				webUserInfo: {}, // 当前平台用户
				// 数据列表
				listData: [],
				totalcount: 0,
				// 查询条件
				pageIndex: 1,
				pageSize: 4,
				// 提示信息弹窗
				msgType: 'success',
				messageText: '这是一条提示信息'
			}
		},
		beforeCreate() {
			that = this;
		},

		mounted() {
			this.webUserInfo = this.$storage.get(Storage_Key.web_user_info, true);
			this.loadData();
		},
		onShow() {},
		computed: {},
		methods: {
			loadData() {
				let formData = {
					pageNum: this.pageIndex,
					pageSize: this.pageSize,
				}
				request({
					url: Platform.api_requestUrl + '/treatment/notice/list',
					data: formData,
					method: 'GET',
				}).then(res => {
					if (res.code == 200 && !!res.rows) {
						this.listData = res.rows;
						this.listData.forEach(element => {
							element.imageUrl = Platform.api_requestUrl + '/' + element.noticepath
						});
					}
				}).catch(error => {
					console.log("fail")
				});
			},
			goMore() {
				// uni.navigateTo({
				// 	url: '/pages/team/team-projects?itemid=' + this.item.id
				// })
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			},
			goDetail(item) {
				let token = uni.getStorageSync('token');
				if (!token) {
					this.messageToggle('error', '请登录后查看!')
					return;
				}
				uni.navigateTo({
					url: '/pages/notice/notice-detail?item=' + encodeURIComponent(JSON.stringify(item))
				})
			},
			messageToggle(type, msg) {
				this.msgType = type;
				this.messageText = msg;
				this.$refs.message.open();
			},
		},
	}
</script>
<style lang='scss' scoped>
	.main-contanier {
		overflow: scroll;

		.head-box {
			font-size: 16px;
			font-weight: bold;
			color: #222;
			margin: 12px 0 8px 16px;
			border-left: 4px solid #2196f3;
			padding-left: 8px;
		}

		.main-box {
			/* flex: 1; */
			overflow: scroll;
			background: #FFFFFF;
			padding-bottom: 3px;
			/* min-height: 86vh; */
		}
	}
</style>